<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>GLFW: Building programs using GLFW</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">GLFW
   &#160;<span id="projectnumber">3.0.1</span>
   </div>
   <div id="projectbrief">A multi-platform library for OpenGL, window and input</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Building programs using GLFW </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#build_include">Including the GLFW header file</a><ul><li class="level2"><a href="#build_macros">GLFW header option macros</a></li>
</ul>
</li>
<li class="level1"><a href="#build_link">Link with the right libraries</a><ul><li class="level2"><a href="#build_link_cmake">Using GLFW from CMake</a></li>
<li class="level2"><a href="#build_link_win32">Windows</a></li>
<li class="level2"><a href="#build_link_unix">Unix with X11</a></li>
<li class="level2"><a href="#build_link_osx">Mac OS X</a></li>
</ul>
</li>
</ul>
</div>
<div class="textblock"><p>This is about compiling and linking programs that use GLFW. For information on how to <em>write</em> such programs, start with the <a class="el" href="quick.html">introductory tutorial</a>.</p>
<h1><a class="anchor" id="build_include"></a>
Including the GLFW header file</h1>
<p>In the files of your program where you use OpenGL or GLFW, you should include the GLFW 3 header file, i.e.:</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="glfw3_8h.html">GLFW/glfw3.h</a>&gt;</span></div>
</div><!-- fragment --><p>This defines all the constants, types and function prototypes of the GLFW API. It also includes the chosen client API header files (by default OpenGL), and defines all the constants and types necessary for those headers to work on that platform.</p>
<p>For example, under Windows you are normally required to include <code>windows.h</code> before including <code>GL/gl.h</code>. This would make your source file tied to Windows and pollute your code's namespace with the whole Win32 API.</p>
<p>Instead, the GLFW header takes care of this for you, not by including <code>windows.h</code>, but rather by itself duplicating only the necessary parts of it. It does this only where needed, so if <code>windows.h</code> <em>is</em> included, the GLFW header does not try to redefine those symbols.</p>
<p>In other words:</p>
<ul>
<li>Do <em>not</em> include the OpenGL headers yourself, as GLFW does this for you</li>
<li>Do <em>not</em> include <code>windows.h</code> or other platform-specific headers unless you plan on using those APIs directly</li>
<li>If you <em>do</em> need to include such headers, do it <em>before</em> including the GLFW one and it will detect this</li>
</ul>
<p>If you are using an OpenGL extension loading library such as <a href="http://glew.sourceforge.net/">GLEW</a>, the GLEW header should also be included <em>before</em> the GLFW one. The GLEW header defines macros that disable any OpenGL header that the GLFW header includes and GLEW will work as expected.</p>
<h2><a class="anchor" id="build_macros"></a>
GLFW header option macros</h2>
<p>These macros may be defined before the inclusion of the GLFW header and affect how that header behaves.</p>
<p><code>GLFW_INCLUDE_GLCOREARB</code> makes the header include the modern <code>GL/glcorearb.h</code> header (<code>OpenGL/gl3.h</code> on Mac OS X) instead of the regular OpenGL header.</p>
<p><code>GLFW_INCLUDE_ES1</code> makes the header include the OpenGL ES 1.x <code>GLES/gl.h</code> header instead of the regular OpenGL header.</p>
<p><code>GLFW_INCLUDE_ES2</code> makes the header include the OpenGL ES 2.0 <code>GLES2/gl2.h</code> header instead of the regular OpenGL header.</p>
<p><code>GLFW_INCLUDE_ES3</code> makes the header include the OpenGL ES 3.0 <code>GLES3/gl3.h</code> header instead of the regular OpenGL header.</p>
<p><code>GLFW_INCLUDE_NONE</code> makes the header not include any client API header.</p>
<p><code>GLFW_INCLUDE_GLU</code> makes the header include the GLU header. This only makes sense if you are using OpenGL.</p>
<p><code>GLFW_DLL</code> is necessary when using the GLFW DLL on Windows, in order to explain to the compiler that the GLFW functions will be coming from another executable.</p>
<h1><a class="anchor" id="build_link"></a>
Link with the right libraries</h1>
<h2><a class="anchor" id="build_link_cmake"></a>
Using GLFW from CMake</h2>
<p>The <code>GLFW_LIBRARIES</code> cache variable contains all link-time dependencies of GLFW as it is currently configured, so to link against GLFW simply do: </p>
<pre class="fragment">target_link_libraries(myapp glfw ${GLFW_LIBRARIES})
</pre><p>Note that this does not include GLU, as GLFW does not use it. If your application needs GLU, you can add it to the list of dependencies with the <code>OPENGL_glu_LIBRARY</code> cache variable.</p>
<h2><a class="anchor" id="build_link_win32"></a>
Windows</h2>
<p>The static version of the GLFW library is named <code>glfw3</code>. When using this version, it is also necessary to link with some libraries that GLFW uses.</p>
<p>When linking a program under Windows that uses the static version of GLFW, you must link with <code>opengl32</code>. If you are using GLU, you must also link with <code>glu32</code>.</p>
<p>The link library for the GLFW DLL is named <code>glfw3dll</code>. When compiling a program that uses the DLL version of GLFW, you need to define the <code>GLFW_DLL</code> macro <em>before</em> any inclusion of the GLFW header. This can be done either with a compiler switch or by defining it in your source code.</p>
<p>A program using the GLFW DLL does not need to link against any of its dependencies, but you still have to link against <code>opengl32</code> if your program uses OpenGL and <code>glu32</code> if it uses GLU.</p>
<h2><a class="anchor" id="build_link_unix"></a>
Unix with X11</h2>
<p>GLFW supports <a href="http://www.freedesktop.org/wiki/Software/pkg-config/">pkg-config</a>, and <code>glfw3.pc</code> file is generated when the library is built and installed along with it. You can use it without installation using the <code>PKG_CONFIG_PATH</code> environment variable. See the documentation for pkg-config for more details.</p>
<p>A typical compile and link command-line when using the static may look like this: </p>
<pre class="fragment">cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --static --libs glfw3`
</pre><p>If you are using the shared library, simply omit the <code>--static</code> flag.</p>
<p>If you are using GLU, you should also add <code>-lGLU</code> to your link flags.</p>
<h2><a class="anchor" id="build_link_osx"></a>
Mac OS X</h2>
<p>GLFW on Mac OS X uses the Cocoa, OpenGL and IOKit frameworks.</p>
<p>If you are using Xcode, you can simply add the GLFW library and these frameworks as dependencies.</p>
<p>If you are building from the command-line, it is recommended that you use pkg-config</p>
<p>GLFW supports <a href="http://www.freedesktop.org/wiki/Software/pkg-config/">pkg-config</a>, and <code>glfw3.pc</code> file is generated when the library is built and installed along with it. You can use it without installation using the <code>PKG_CONFIG_PATH</code> environment variable. See the documentation for pkg-config for more details.</p>
<p>You can find pkg-config in most package systems such as <a href="http://www.finkproject.org/">Fink</a> and <a href="http://www.macports.org/">MacPorts</a>, so if you have one of them installed, simply install pkg-config. Once you have pkg-config available, the command-line for compiling and linking your program is: </p>
<pre class="fragment">cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --static --libs glfw3`
</pre><p>If you do not wish to use pkg-config, you need to add the required frameworks and libraries to your command-line using the <code>-l</code> and <code>-framework</code> switches, i.e.: </p>
<pre class="fragment">cc -o myprog myprog.c -lglfw -framework Cocoa -framework OpenGL -framework IOKit
</pre><p>Note that you do not add the <code>.framework</code> extension to a framework when adding it from the command-line.</p>
<p>The OpenGL framework contains both the OpenGL and GLU APIs, so there is no need to add additional libraries or frameworks when using GLU. Also note that even though your machine may have <code>libGL</code>-style OpenGL libraries, they are for use with the X Window System and will <em>not</em> work with the Mac OS X native version of GLFW. </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Sun Jun 16 2013 22:34:04 for GLFW by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.3.1
</small></address>
</body>
</html>
